package com.lxb.eduservice.controller.front;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lxb.commonutils.R;
import com.lxb.eduservice.entity.EduCourse;
import com.lxb.eduservice.entity.EduTeacher;
import com.lxb.eduservice.service.EduCourseService;
import com.lxb.eduservice.service.EduTeacherService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 前台，讲师接口
 *
 * @author xuebin.li
 * @createTime 2023/1/3 13:16
 */
@Api(description = "前台，讲师接口")
@RestController
@RequestMapping("/eduservice/teacherFront")
//@CrossOrigin
public class TeacherFrontController {

    @Autowired
    private EduTeacherService teacherService;
    @Autowired
    private EduCourseService courseService;

    @ApiOperation("分页查询讲师接口")
    @GetMapping("/getTeacherFrontList/{page}/{limit}")
    public R getTeacherFrontList(@PathVariable long page, @PathVariable long limit) {

        Page<EduTeacher>  teacherPage = new Page<>(page, limit);

        //调用分页方法
        Map<String, Object> map = teacherService.pageTearchar(teacherPage);

        //返回分页数据
        return R.ok().data(map);
    }

    @ApiOperation("根据id获取讲师所讲课程列表")
    @GetMapping("/selectByTeacherId/{id}")
    public R selectByTeacherId(@PathVariable String id){

        //1.根据讲师id，返回讲师信息
        EduTeacher teacher = teacherService.getById(id);

        //2.根据讲师id，查询该讲师教授的课程
        List<EduCourse> courseList = courseService.selectByTeacherID(id);

        return R.ok().data("teacher",teacher).data("courseList",courseList);
    }

}
